﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CAATS_Registration
{
    public partial class caats_step5 : System.Web.UI.Page
    {
        public Int32 m_nMemberCnt;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;
            GardenViewRoom.Text = dataRecord.Instance()._strGVRCnt;
            OceanViewRoom.Text = dataRecord.Instance()._strOVRCnt;
            GrandOceanViewRoom.Text = dataRecord.Instance()._strGOVRCnt;
            txtDateCheckIn.Text = dataRecord.Instance()._strDateCheckIn;
            txtDateDeparture.Text = dataRecord.Instance()._strDateDeparture;
            Int32 nCnt;
            nCnt = Convert.ToInt32(dataRecord.Instance()._strMemberCnt);
            m_nMemberCnt = nCnt;
            HtmlTableRow[] MemberInfo = new HtmlTableRow[5];
            MemberInfo[0] = MemberInfo1;
            MemberInfo[1] = MemberInfo2;
            MemberInfo[2] = MemberInfo3;
            MemberInfo[3] = MemberInfo4;
            MemberInfo[4] = MemberInfo5;
            for (Int32 i = 0; i < 5; i++)
            {
                MemberInfo[i].Visible = false;
            }
            for (Int32 i = 0; i < nCnt; i++)
            {
                MemberInfo[i].Visible = true;
            }

            double fFee = 0.0;
            if(nCnt > 0 )
            {
                if ( !dataRecord.Instance().m_bPersonal)
                {
                    fFee = nCnt * 500.00 + 500.00;
                }
                else
                {
                    fFee = nCnt * 800.00;
                }
                  


            }
            Label_TotalDue.Text = "$" + fFee.ToString();
        }

        protected void Back_Click(object sender, EventArgs e)
        {
            Server.Transfer("caats_step4.aspx?name=step4", true); 
        }

        protected void Next_Click(object sender, EventArgs e)
        {
            Int32 nCnt;
            nCnt = Convert.ToInt32(dataRecord.Instance()._strMemberCnt);
            m_nMemberCnt = nCnt;
            DBConnection.Active = DBConnection.Open("127.0.0.1", "info", "root", "daiguanzhong");

            //如果连接失败，提示并退出
            if (DBConnection.Active == null)
            {
            }
            else
            {
            }
            string strSQL = "";
            for (int i = 0; i < m_nMemberCnt; i++  )
            {
                strSQL = "INSERT INTO `info`.`info` (`FullName`, `Title`, `School`, `Country`, `FullAddress`, `Organization`, `Tel`, `Fax`, `EMail`, `PassportNumber`, `DateOfIssue`, `DateOfExpiry`, `PRC`, `Nationality`, `GVRCnt`, `OVRCnt`, `GOVRCnt`, `DateCheckIn`, `DateDeparture`, `GVRSmokingCnt`, `OVRSmokingCnt`, `GOVRSmokingCnt`) ";
                strSQL += "VALUES ('";
                //strSQL += "', ''";
                strSQL += dataRecord.Instance().m_listInfos[i]._strFullName;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strTitle;
                strSQL += "', '";
                strSQL += dataRecord.Instance().organization;
                strSQL += "', '";
                strSQL += dataRecord.Instance().country;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strFullAddress;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strStateOrganization;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strTel;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strFax;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strEmail;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strpassportNumber;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strDateofIssue;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strDateofExpiry;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strPRC;
                strSQL += "', '";
                strSQL += dataRecord.Instance().m_listInfos[i]._strNationality;
                if ( i == 0 )
                {
                    strSQL += "', '";
                    strSQL += dataRecord.Instance()._strGVRCnt;
                    strSQL += "', '";
                    strSQL += dataRecord.Instance()._strOVRCnt;
                    strSQL += "', '";
                    strSQL += dataRecord.Instance()._strGOVRCnt;
                    strSQL += "', '";
                    strSQL += dataRecord.Instance()._strDateCheckIn;
                    strSQL += "', '";
                    strSQL += dataRecord.Instance()._strDateDeparture;
                    strSQL += "', '";
                    strSQL += dataRecord.Instance()._strGVRSmokingCnt;
                    strSQL += "', '";
                    strSQL += dataRecord.Instance()._strOVRSmokingCnt;
                    strSQL += "', '";
                    strSQL += dataRecord.Instance()._strGOVRSmokingCnt;
                }
                else
                {
                    strSQL += "', '";
                    strSQL += "";
                    strSQL += "', '";
                    strSQL += "";
                    strSQL += "', '";
                    strSQL += "";
                    strSQL += "', '";
                    strSQL += "";
                    strSQL += "', '";
                    strSQL += "";
                    strSQL += "', '";
                    strSQL += "";
                    strSQL += "', '";
                    strSQL += "";
                    strSQL += "', '";
                    strSQL += "";
                }
                strSQL += "')";
                //DBConnection.Active.Execute("VALUES ('water', 'manager', 'nwpu', 'china', '牡丹园', 'heegle', '022', '022', 'mhm15191@msn.com', '486546', '4564', '4564', '456', 'amera')");

                //strSQL = "INSERT INTO `info`.`info` (`FullName`, `Title`, `School`, `Country`, `FullAddress`, `Organization`, `Tel`, `Fax`, `EMail`, `PassportNumber`, `DateOfIssue`, `DateOfExpiry`, `PRC`, `Nationality`) VALUES ('p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p-p', 'p-p', 'p', 'p')";
                DBConnection.Active.Execute(strSQL);


            }
            Server.Transfer("caats_step6.aspx?name=step6", true);
            DBConnection.Active.Dispose();
        }



    }
}
